<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js\Jquery3.1.1.js"></script>
</head>
<body>
<button>自动查找服务器</button>
<div>
    正在尝试IP：<span id="chekIP"></span>
</div>
</body>
<script>
    $("button").click(function () {
        alert("aaaa");
        $.ajax({
            url: 'FindServiceIpAddres'
        })
    });
    var ip = "";
    var port = "";
    $.ajax({
        url: 'getIPandPort',
        async: false,
        success: function (res) {
            port = res.port;
            ip = res.ip;
        }
    });
    var ws = new WebSocket("ws://" + ip + ":" + port + "/sokect");
    ws.onmessage = function (evt) {
        var msg = JSON.parse(evt.data);
        if (msg.statusCode == "0") {
            alert(msg.message + ":" + msg.ip);
        }
        if (msg.statusCode == "-1") {
            alert("找不到服务器");
        }
        if (msg.from == "FindServer") {
            $("#chekIP").html(msg.checkIP);
        }

    }
</script>
</html>